import { getTradeList, deleteTrade } from '@/api/product/tradMark'
const state = {
  tradeList: {}
}
const actions = {
  async deleteTradeAsync(_, payload) {
    const res = await deleteTrade(payload)
    if (res.code === 200) {
      return 'ok'
    } else {
      return Promise.reject(new Error('reject'))
    }
  },
  async updateTradeAsync(store, payload) {
    const res = await this._vm.$API.tradeMark.updateOrSaveTrade(payload)
    if (res.code === 200) {
      this._vm.$message({ message: payload.id ? '修改品牌成功' : '添加品牌成功', showClose: true, type: 'success' })
      return '修改成功'
    } else {
      return Promise.reject(new Error('修改失败'))
    }
  },
  async getTradeListAsync(store, payload) {
    const result = await getTradeList(payload)
    if (result.code === 200) {
      store.commit('GETTRADELIST', result.data)
    }
  }
}
const mutations = {
  GETTRADELIST(state, payload) {
    state.tradeList = payload
  }
}
export default {
  state, actions, mutations
}
